home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJLSR200.ZIP / src / libc / ansi / stdio / remove.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-31  |  1.2 KB  |  49 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <libc/stubs.h>
  3. #include <io.h>
  4. #include <stdio.h>
  5. #include <errno.h>
  6. #include <dpmi.h>
  7. #include <go32.h>
  8. #include <libc/dosio.h>
  9.  
  10. int
  11. remove(const char *fn)
  12. {
  13.   __dpmi_regs r;
  14.   unsigned attr;
  15.   int directory_p;
  16.  
  17.   /* Get the file attribute byte.  */
  18.   attr = _chmod(fn, 0);
  19.   directory_p = attr & 0x10;
  20.  
  21.   /* Now, make the file writable.  We must reset Vol, Dir, Sys and Hidden bits 
  22.      in addition to the Read-Only bit, or else 214301 will fail.  */
  23.   _chmod(fn, 1, attr & 0xffe0);
  24.  
  25.   /* Now delete it.  Note, _chmod leave dir name in tranfer buffer. */
  26.   if (directory_p)
  27.     r.h.ah = 0x3a;        /* DOS Remove Directory function */
  28.   else
  29.     r.h.ah = 0x41;        /* DOS Remove File function */
  30.   if(_USE_LFN) {
  31.     r.h.al = r.h.ah;
  32.     r.h.ah = 0x71;
  33.     r.x.si = 0;            /* No Wildcards */
  34.   }
  35.   r.x.dx = __tb_offset;
  36.   r.x.ds = __tb_segment;
  37.   __dpmi_int(0x21, &r);
  38.   if(r.x.flags & 1)
  39.   {
  40.     /* We failed.  Leave the things as we've found them.  */
  41.     int e = __doserr_to_errno(r.x.ax);
  42.  
  43.     _chmod(fn, 1, attr & 0xffe7);
  44.     errno = e;
  45.     return -1;
  46.   }
  47.   return 0;
  48. }
  49.